package com.quanyan.place.service.impl;

import com.quanyan.api.APIResponse;
import com.quanyan.common.constants.Constants;
import com.quanyan.common.utils.CommonUtils;
import com.quanyan.place.entity.apiresp.RespOrderNo;
import com.quanyan.place.service.ApiPlaceInsideService;
import org.apache.commons.collections.MapUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Map;

/**
 * Created by Kingson.chan on 2016/8/25 0025.
 */
@Service("apiPlaceInsideService")
public class ApiPlaceInsideServiceImpl implements ApiPlaceInsideService {
    @Autowired
    CardNoServiceImpl cardNoService;

    /**
     * 获取订单号和流水号
     * @param map
     * @return
     */
    @Override
    public APIResponse<RespOrderNo> getOrderNoAndNo(Map map) {
        Integer uid = MapUtils.getInteger(map, "uid");
        Integer placeId = MapUtils.getInteger(map, "placeId");
        if(uid == null || placeId == null){
            return APIResponse.returnFail("输入参数不能为空");
        }
        String orderNo = CommonUtils.generateBusinessOrderNo(Constants.PLACE_SYSTEM, uid);
        RespOrderNo respOrderNo = new RespOrderNo();
        respOrderNo.setOrderNo(orderNo);
        respOrderNo.setNo(CommonUtils.generateNo(placeId));
        return APIResponse.returnSuccess(respOrderNo);
    }

    /**
     * 获取卡号
     * @param map
     * @return
     */
    @Override
    public String getCardNo(Map map) {
        return cardNoService.getCardNo(map);
    }

    /**
     * 获取流水号
     * @param map
     * @return
     */
    @Override
    public String getNo(Map map) {
        Integer placeId = MapUtils.getInteger(map, "placeId");
        return CommonUtils.generateNo(placeId);
    }
}
